//
//  ImageReplacerAppDelegate.m
//  ImageReplacer
//
//  Created by Tyler Powell on 4/30/12.
//  Copyright 2012 Georgia Institute of Technology. All rights reserved.
//

#import "ImageReplacerAppDelegate.h"

@implementation ImageReplacerAppDelegate

@synthesize window;
@synthesize launcher;
@synthesize writer;

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
	//code to run when app launches
	//createFile(@"images.txt");
	//createFile(@"options.txt");
    //createFile(@"enabledButtons.txt");
    //createFile(@"disabledButtons.txt");
    //if(countLines(@"options.txt")<7)
    //    initializeOptions();
    //NSString* checkboxstate = getItemFromFileAtIndex(@"options.txt", 2);
    //[[launcher randomizeCheckBox] setState:[checkboxstate longLongValue]];
    NSError *err = nil;
    NSString *appName = [[[NSBundle mainBundle] bundlePath] lastPathComponent];
    if ([[NSFileManager defaultManager]fileExistsAtPath:@"/Applications/temp.app"] && ![appName isEqualToString:@"temp.app"]) {
        [[NSFileManager defaultManager]removeItemAtPath:@"/Applications/temp.app" error:&err];
    }
    if ([writer needsUpdate]) {
        [writer updateApp];
    }
    [self updateDockMenu:self];
    //[window ];
    //writer = [[FileWriter alloc]init];

}

- (BOOL) applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender{
    return YES;
}

- (NSMenu*)applicationDockMenu:(NSApplication *)sender{
    
    return dynamicMenu;
}

-(IBAction)updateDockMenu:(id)sender;
{
    if (dynamicMenu == nil) {
        dynamicMenu = [[NSMenu alloc] init];
        [dynamicMenu setAutoenablesItems:NO];
        dynamicItem = [dynamicMenu addItemWithTitle:@"Launch iLoL" action:@selector(launchiLoL:) keyEquivalent:@""];
        [dynamicItem setTarget:launcher];
        [dynamicItem setEnabled:YES];
    }
}



@end
